```bash
composer create-project laravel/laravel captcha-login
cd captcha-login
```
We need to install the `guzzlehttp/guzzle` package to handle HTTP requests and `anhskohbo/no-captcha` package to integrate Google reCAPTCHA with Laravel.
```bash
composer require guzzlehttp/guzzle
composer require anhskohbo/no-captcha
```
```dotenv
RECAPTCHA_SITE_KEY=your_site_key_here
RECAPTCHA_SECRET_KEY=your_secret_key_here
```
Let's create a middleware that will handle the captcha verification before allowing users to log in.
```bash
```
```php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use NoCaptcha;
class VerifyCaptcha
{
public function handle(Request $request, Closure $next)
{
$response = $request->input('g-recaptcha-response');
if (!empty($response)) {
if (!$captcha->isSuccess()) {
return redirect()->back()->withErrors(['captcha' => 'Failed to verify captcha. Please try again.']);
}
} else {
return redirect()->back()->withErrors(['captcha' => 'Please complete the captcha to proceed.']);
}
return $next($request);
}
}
```
```php
protected $routeMiddleware = [
// other middleware
];
```
```php
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->middleware('captcha')->only('login');
}
```
In your login view, include the Google reCAPTCHA widget.
```blade
```
```php
```
That's it! Now, your Laravel 8 application should have a captcha login feature using Google reCAPTCHA. Users will need to complete the captcha verification before logging in, adding an additional layer of security to your login process.